package com.zhlwish.dbunitdemo.dao;

import java.sql.Connection;
import java.sql.DriverManager;

public class BaseDao {

	private static Connection CONNECTION_INSTANCE = null;

	protected Connection getConnection() throws Exception {
		if (null == CONNECTION_INSTANCE) {
			Class.forName("com.mysql.jdbc.Driver");
			CONNECTION_INSTANCE = DriverManager.getConnection(
					"jdbc:mysql://127.0.0.1:3306/dbunitdemo", "root", "123456");
		}
		return CONNECTION_INSTANCE;
	}
	
	protected void closeConnection() throws Exception{
		if(null != CONNECTION_INSTANCE){
			if(!CONNECTION_INSTANCE.isClosed()){
				CONNECTION_INSTANCE.close();
			}
			CONNECTION_INSTANCE = null;
		}
	}

}
